package mumethod;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import mudbconnection.DBPhysicalSimpleSummary;
import mudbconnection.DBPhysicals;
import mudbconnection.DBQuestionnaireSimpleSummary;
import mudbconnection.DBScores;
import mudbconnection.DBStudentSummaryService;
import mudbconnection.DBStudents;
import muobject.Physical;
import muobject.ChartSexBean;
import muobject.PhysicalSimpleSummary;
import muobject.QuestionnaireSimpleSummary;
import muobject.Student;
import muobject.StudentSummary;

@Component("ReportGeneratorService")
public class ReportGeneratorService implements ReportGenerator {

	@Autowired
	private DBStudents dbStudents;
	@Autowired
	private DBPhysicals dbPhysicals;
	@Autowired
	private DBScores dbScores;
	@Autowired
	private DBStudentSummaryService dbStudentSummaryService;
	@Autowired
	private AccessQuestionnaires getQuestionnaires;
	@Autowired
	private AccessQuestions getQuestions;
	@Autowired
	private DBPhysicalSimpleSummary  getPhysicalSimpleSummary;
	@Autowired
	private DBQuestionnaireSimpleSummary  dbQuestionnaireSimpleSummary;
	
	private DateControl dateControl;
	private LibFunction libFunction;
	List<PhysicalSimpleSummary> physicalSimpleSummarys;
	
	public ReportGeneratorService(){
		dateControl = new LibFunction();
		libFunction = new LibFunction();
		physicalSimpleSummarys = new ArrayList<PhysicalSimpleSummary>();
	}
	
	public List<Student> getTableStudents(String sno,
			List<String> years, List<String> grades, List<String> sclasses,
			List<String> stnos){
		
		List<Student> students = new ArrayList<Student>();
		
		if(!stnos.isEmpty()) {
			for (String yearstr : years) {
				for(String gradestr : grades){
					for (String sclassstr : sclasses) {
						for (String stnostr : stnos) {
							for (Student student : dbStudents.getAssignStudents(sno, yearstr, gradestr, sclassstr, stnostr))
								students.add(student);
						}
					}
				}
				
			}
		}else if(!sclasses.isEmpty()) {
			for(String yearstr : years) {
				for(String gradestr : grades){
					for (String sclassstr : sclasses) {
						for (Student student : dbStudents.getSpicalYearStudents(sno, yearstr, gradestr, sclassstr))
							students.add(student);
					}
				}
			}
		}else if(!grades.isEmpty()) {
			for(String yearstr : years) {
				for(String gradestr : grades){
					for (Student student : dbStudents.getSpicalYearStudents(sno, yearstr, gradestr, "%"))
						students.add(student);
				}
			}
		}else if(!years.isEmpty()) {
			for(String yearstr : years) {
				for (Student student : dbStudents.getSpicalYearStudents(sno, yearstr, "%", "%"))
					students.add(student);
			}
		}
		
		return students;
	}
	
	public List<PhysicalSimpleSummary> getPhysicalSimpleSummary(String sno,
			List<String> years, List<String> grades, List<String> sclasses,
			List<String> stnos) {

		physicalSimpleSummarys = new ArrayList<PhysicalSimpleSummary>();
		List<Student> students = new ArrayList<Student>();
		
		students = getTableStudents(sno, years, grades, sclasses, stnos);

		for(Student student : students){
			List<Physical> StudentPhysicals = dbPhysicals.getSpicalStudentPhysicals(student.getStno(), student.getYears());
			if(StudentPhysicals != null)
			for(Physical physical : StudentPhysicals){
				double totalScore;
				int levelScore;
				int age = dateControl.getStudentAge(student.getBirthday(), physical.getTestDate());
				int hwScore = dbScores.getHWScore(student.getSex(), dateControl.getStudentAge(student.getBirthday(), physical.getTestDate()), physical.getHeight(), physical.getWeight());
				int gripScore = dbScores.getPhysicalScore(student.getSex(), age, "handgrip", physical.getGrip());
				int jumpScore = dbScores.getPhysicalScore(student.getSex(), age, "standhop", physical.getJump());
				int sitScore = dbScores.getPhysicalScore(student.getSex(), age, "sitreach", physical.getSitup());
				int vcaScore = dbScores.getPhysicalScore(student.getSex(), age, "lung", physical.getVcapacity());
				int run69Score = dbScores.getPhysicalScore(student.getSex(), age, "runwalk", physical.getRun69());
				int run15Score = dbScores.getPhysicalScore(student.getSex(), age, "runwalk", physical.getRun15());
				if(physical.getRun69() != 0 & physical.getRun15() != 0 & physical.getVcapacity() != 0){
					totalScore = (((double)(hwScore + gripScore + jumpScore + sitScore + vcaScore+ run69Score + run15Score)/35) * 100) * 0.3;
				}else if(physical.getRun69() == 0 & physical.getRun15() == 0 & physical.getVcapacity() == 0){
					totalScore = (((double)(hwScore + gripScore + jumpScore + sitScore + vcaScore+ run69Score + run15Score)/20) * 100) * 0.3;
				}else if((physical.getRun69() == 0 & physical.getRun15() == 0) | 
						(physical.getRun69() == 0 & physical.getVcapacity() == 0) |
						(physical.getRun15() == 0 & physical.getVcapacity() == 0)){
					totalScore = (((double)(hwScore + gripScore + jumpScore + sitScore + vcaScore+ run69Score + run15Score)/25) * 100) * 0.3;
				}else{
					totalScore = (((double)(hwScore + gripScore + jumpScore + sitScore + vcaScore+ run69Score + run15Score)/30) * 100) * 0.3;
				}
				totalScore = libFunction.doublePoint(totalScore);
				if(totalScore > 26 & totalScore < 30){
					levelScore = 1;
				}else if(totalScore >= 22 & totalScore < 26){
					levelScore = 2;
				}else if(totalScore >= 15 & totalScore < 22){
					levelScore = 3;
				}else if(totalScore >= 10 & totalScore < 15){
					levelScore = 4;
				}else{
					levelScore = 5;
				}
				physicalSimpleSummarys.add(new PhysicalSimpleSummary(student.getYears(), student.getGrade(), student.getSclass()
						, student.getStno(), student.getClassno(), student.getEname(), student.getCname(), student.getSex()
						, age, dateControl.getDateString(physical.getTestDate())
						, hwScore, gripScore, jumpScore, sitScore, vcaScore, run69Score, run15Score
						, totalScore, levelScore));
			}
		}
		return physicalSimpleSummarys;
	}

	public List<QuestionnaireSimpleSummary> getQuestionnaireSimpleSummary(String sno,
			List<String> years, List<String> grades, List<String> sclasses,
			List<String> stnos) {
		
		List<QuestionnaireSimpleSummary> questionnaireSimpleSummarys = new ArrayList<QuestionnaireSimpleSummary> ();
		List<Student> students = new ArrayList<Student>();
		
		students = getTableStudents(sno, years, grades, sclasses, stnos);
		
		for(Student student : students){
			List<Map> testDates = getQuestionnaires.getTestDateByYearStno(student.getStno(), student.getYears());
			
			for(Map testDateMap : testDates){
				double dtotalscore = 0;
		        double ftotalscore = 0;
		        int dtotalcount = 0;
	            int ftotalcount = 0;
	            int dqcount = getQuestions.getQuestionCountByYear(student.getYears(), "Day");
	            int fqcount = getQuestions.getQuestionCountByYear(student.getYears(), "Food");
	            String testDate = dateControl.convertDate(testDateMap.get("TestDate").toString());
				int age = dateControl.getStudentAge(student.getBirthday(), dateControl.getStringDate(testDate));
				QuestionnaireSimpleSummary questionnaireSimpleSummary = 
						new QuestionnaireSimpleSummary(student.getYears(), student.getGrade(), student.getSclass(),
								student.getStno(), student.getClassno(), student.getEname(), student.getCname(), 
								student.getSex(), age, testDate, 0, 0, 0,
						0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0);
				
				List listAnswer = getQuestionnaires.getListAnswerByYearTestdateStno(student.getStno(), student.getYears(), testDate);
				
		        if(listAnswer != null){
		            Iterator it = listAnswer.iterator();
		            while(it.hasNext()) {
		                Map answerMap = (Map) it.next();
		                String Qno = answerMap.get("Qno").toString();
		                if(Qno.equals("D1")){
		                	questionnaireSimpleSummary.setD1score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D2")){
							questionnaireSimpleSummary.setD2score(Integer.valueOf(answerMap.get("Answer").toString()));
							dtotalcount++;
						}else if(Qno.equals("D3")){
							questionnaireSimpleSummary.setD3score(Integer.valueOf(answerMap.get("Answer").toString()));
							dtotalcount++;
						}else if(Qno.equals("D4")){
							questionnaireSimpleSummary.setD4score(Integer.valueOf(answerMap.get("Answer").toString()));
							dtotalcount++;
						}else if(Qno.equals("D5")){
		                	questionnaireSimpleSummary.setD5score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D6")){
		                	questionnaireSimpleSummary.setD6score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D7")){
		                	questionnaireSimpleSummary.setD7score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D8")){
		                	questionnaireSimpleSummary.setD8score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D9")){
		                	questionnaireSimpleSummary.setD9score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D10")){
		                	questionnaireSimpleSummary.setD10score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D11")){
		                	questionnaireSimpleSummary.setD11score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D12")){
		                	questionnaireSimpleSummary.setD12score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D13")){
		                	questionnaireSimpleSummary.setD13score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D14")){
		                	questionnaireSimpleSummary.setD14score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("D15")){
		                	questionnaireSimpleSummary.setD15score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	dtotalcount++;
						}else if(Qno.equals("F1")){
		                	questionnaireSimpleSummary.setF1score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F2")){
		                	questionnaireSimpleSummary.setF2score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F3")){
		                	questionnaireSimpleSummary.setF3score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F4")){
		                	questionnaireSimpleSummary.setF4score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F5")){
		                	questionnaireSimpleSummary.setF5score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F6")){
		                	questionnaireSimpleSummary.setF6score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F7")){
		                	questionnaireSimpleSummary.setF7score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F8")){
		                	questionnaireSimpleSummary.setF8score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F9")){
		                	questionnaireSimpleSummary.setF9score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}else if(Qno.equals("F10")){
		                	questionnaireSimpleSummary.setF10score(Integer.valueOf(answerMap.get("Answer").toString()));
		                	ftotalcount++;
						}		                
		            }
		        }
		        if(dqcount != 0){
		        	dtotalscore = (double)((double)(questionnaireSimpleSummary.getD1score() + questionnaireSimpleSummary.getD2score() + 
		        			questionnaireSimpleSummary.getD3score() + questionnaireSimpleSummary.getD4score() + 
		        			questionnaireSimpleSummary.getD5score() + questionnaireSimpleSummary.getD6score() + 
		        			questionnaireSimpleSummary.getD7score() + questionnaireSimpleSummary.getD8score() + 
		        			questionnaireSimpleSummary.getD9score() + questionnaireSimpleSummary.getD10score() + 
		        			questionnaireSimpleSummary.getD11score() + questionnaireSimpleSummary.getD12score() + 
		        			questionnaireSimpleSummary.getD13score() + questionnaireSimpleSummary.getD14score() + 
		        			questionnaireSimpleSummary.getD15score())/(dqcount * 4))*100*0.4;
		        }
		        if(fqcount != 0){
		        	ftotalscore = (double)((double)(questionnaireSimpleSummary.getF1score() + questionnaireSimpleSummary.getF2score() + 
		        			questionnaireSimpleSummary.getF3score() + questionnaireSimpleSummary.getF4score() + 
		        			questionnaireSimpleSummary.getF5score() + questionnaireSimpleSummary.getF6score() + 
		        			questionnaireSimpleSummary.getF7score() + questionnaireSimpleSummary.getF8score() + 
		        			questionnaireSimpleSummary.getF9score() + 
		        			questionnaireSimpleSummary.getF10score())/(fqcount *4))*100*0.3;
		        }
		        questionnaireSimpleSummary.setDtotalscore(libFunction.doublePoint(dtotalscore));
		        questionnaireSimpleSummary.setFtotalscore(libFunction.doublePoint(ftotalscore));
		        System.out.println(questionnaireSimpleSummary.getClassno() + " " + questionnaireSimpleSummary.getTestdate());
		        questionnaireSimpleSummarys.add(questionnaireSimpleSummary);
			}
		}
		
		return questionnaireSimpleSummarys;
	}

	public List<StudentSummary> getStudentSummary(String sno,
			List<String> years, List<String> grades, List<String> sclasses,
			List<String> stnos){
		
		List<StudentSummary> studentSummarys = new ArrayList<StudentSummary>();
		List<Student> students = new ArrayList<Student>();
		List<StudentSummary> tempStudentSummarys = new ArrayList<StudentSummary> ();
		
		students = getTableStudents(sno, years, grades, sclasses, stnos);
		int i=0;
		for(Student student : students){
			studentSummarys.addAll(dbStudentSummaryService.getStudentSummaryFromOtherTable(student.getYears(), student.getStno()));
		}
		for(StudentSummary studentSummary : studentSummarys){
			java.util.Date date = new java.util.Date();
			studentSummary.setAge(libFunction.getStudentAge(studentSummary.getBirthday(), date));
			double height = studentSummary.getHeight();
			double weight = studentSummary.getWeight();
			studentSummary.setBMI(libFunction.doublePoint(height!=0&weight!=0? weight/(height*height/10000) : 0));
			studentSummary.setStandard(libFunction.StandardBMI(studentSummary.getSex(), studentSummary.getAge(), studentSummary.getBMI()));
			int vacpacityNo = libFunction.getAdvice(studentSummary.getVcapacityscore(), 4);
			studentSummary.setPcomment1(dbScores.getAdviceScore("advice", "vacpacity", vacpacityNo));
			studentSummary.setDcomment1(dbScores.getAdviceScore("dosport", "vacpacity", vacpacityNo));
			int gripNo = libFunction.getAdvice(studentSummary.getGripscore(), 4);
			studentSummary.setPcomment2(dbScores.getAdviceScore("advice", "grip", gripNo));
			studentSummary.setDcomment2(dbScores.getAdviceScore("dosport", "grip", gripNo));
			int jumprun69No = libFunction.getAdvice(studentSummary.getJumpscore()+studentSummary.getRun69score(), 8);
			studentSummary.setPcomment3(dbScores.getAdviceScore("advice", "jumprun69", jumprun69No));
			studentSummary.setDcomment3(dbScores.getAdviceScore("dosport", "jumprun69", jumprun69No));
			int run15No = libFunction.getAdvice(studentSummary.getSitupscore(), 4);
			studentSummary.setPcomment4(dbScores.getAdviceScore("advice", "run15", run15No));
			studentSummary.setDcomment4(dbScores.getAdviceScore("dosport", "run15", run15No));
			int total = studentSummary.getDtotalscore()+studentSummary.getFtotalscore()+studentSummary.getTotalscore();
			studentSummary.setTotal(total);
			studentSummary.setAward(libFunction.getAward(total));
			tempStudentSummarys.add(studentSummary);
			System.out.println(studentSummary.getEname() + " " + (i++));
		}
		studentSummarys = tempStudentSummarys;
		
		return studentSummarys;
	}
	
	public List<ChartSexBean> getPhysicalSexChart(){
		List<ChartSexBean> physicalSexCharts = new ArrayList<ChartSexBean>();
		ChartSexBean physicalSexChart;
		double mValue, fValue, mTotal, fTotal, mfTotal;
		List<String> items = new ArrayList<String>();
		items.add("gripscore");
		items.add("jumpscore");
		items.add("situpscore");
		items.add("vcapacityscore");
		items.add("run69score");
		items.add("run15score");
		items.add("totalscore");
		mTotal = 0;
		fTotal = 0;
		for(String item : items){
			if(!item.equals("totalscore")){
				mTotal += getPhysicalSimpleSummary.getPhysicalSexScoreAvg("M", item);
				fTotal += getPhysicalSimpleSummary.getPhysicalSexScoreAvg("F", item);
			}
		}
		for(String item : items){
			mValue = getPhysicalSimpleSummary.getPhysicalSexScoreAvg("M", item);
			fValue = getPhysicalSimpleSummary.getPhysicalSexScoreAvg("F", item);
			if(item.equals("totalscore")){
				mfTotal = mValue + fValue;
				mValue = (mValue/mfTotal) * 100;
				fValue = (fValue/mfTotal) * 100;
			}else{
				mValue = (mValue/mTotal) * 100;
				fValue = (fValue/fTotal) * 100;
			}
			physicalSexChart = new ChartSexBean("", "", 0, 0);
			physicalSexChart.setSerieas(libFunction.ItemNameConvert(item));
			physicalSexChart.setCategory(libFunction.ItemNameConvert(item));
			physicalSexChart.setmValue(mValue);
			physicalSexChart.setfValue(fValue);
			physicalSexCharts.add(physicalSexChart);
		}
		return physicalSexCharts;
	}
	
	public List<Double> getPhysicalSexChartTable(String item){
		List<Double> values = new ArrayList<Double>();
		for(int Score=1; Score<=5; Score++){
			values.add((double)getPhysicalSimpleSummary.getPhysicalSexScoreCount("M", item, Score));
		}
		values.add((double)getPhysicalSimpleSummary.getPhysicalSexScoreCount("M", item, 0));
		values.add(libFunction.doublePoint(getPhysicalSimpleSummary.getPhysicalSexScoreAvg("M", item)));
		for(int Score=1; Score<=5; Score++){
			values.add((double)getPhysicalSimpleSummary.getPhysicalSexScoreCount("F", item, Score));
		}
		values.add((double)getPhysicalSimpleSummary.getPhysicalSexScoreCount("F", item, 0));
		values.add(libFunction.doublePoint(getPhysicalSimpleSummary.getPhysicalSexScoreAvg("F", item)));
		return values;
	}
	
	public List<ChartSexBean> getDQuestionnaireSexChart(){
		List<ChartSexBean> dQuestionnaireSexCharts = new ArrayList<ChartSexBean>();
		ChartSexBean dQuestionnaireSexChart;
		double mValue, fValue;
		List<String> items = new ArrayList<String>();
		items.add("d1score");
		items.add("d2score");
		items.add("d3score");
		items.add("d4score");
		items.add("d5score");
		items.add("d6score");
		items.add("d7score");
		items.add("d8score");
		items.add("d9score");
		items.add("d10score");
		items.add("d11score");
		items.add("d12score");
		items.add("d13score");
		items.add("d14score");
		items.add("d15score");
		for(String item : items){
			mValue = dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("M", item);
			fValue = dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("F", item);
			dQuestionnaireSexChart = new ChartSexBean("", "", 0, 0);
			if(!(mValue == 0 & fValue == 0)){
				dQuestionnaireSexChart.setSerieas(libFunction.ItemNameConvert(item));
				dQuestionnaireSexChart.setCategory(libFunction.ItemNameConvert(item));
				dQuestionnaireSexChart.setmValue(mValue);
				dQuestionnaireSexChart.setfValue(fValue);
				dQuestionnaireSexCharts.add(dQuestionnaireSexChart);
			}
		}
		return dQuestionnaireSexCharts;
	}
	
	public List<Double> getQuestionnaireSexChartTable(String item){
		List<Double> values = new ArrayList<Double>();
		double mTotal, fTotal;
		
		mTotal = (double)dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreCount("M", item, 0);
		for(int Score=1; Score<=4; Score++){
			int mCount = (int)(dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreCount("M", item, Score)/mTotal * 100);
			values.add((double)mCount);
		}
		values.add(mTotal);
		values.add(libFunction.doublePoint(dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("M", item)));
		
		fTotal = (double)dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreCount("F", item, 0);
		for(int Score=1; Score<=4; Score++){
			int fCount = (int)(dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreCount("F", item, Score)/fTotal * 100);
			values.add((double)fCount);
		}
		values.add(fTotal);
		values.add(libFunction.doublePoint(dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("F", item)));
		return values;
	}
	
	public List<ChartSexBean> getFQuestionnaireSexChart(){
		List<ChartSexBean> fQuestionnaireSexCharts = new ArrayList<ChartSexBean>();
		ChartSexBean fQuestionnaireSexChart;
		double mValue, fValue;
		List<String> items = new ArrayList<String>();
		items.add("f1score");
		items.add("f2score");
		items.add("f3score");
		items.add("f4score");
		items.add("f5score");
		items.add("f6score");
		items.add("f7score");
		items.add("f8score");
		items.add("f9score");
		items.add("f10score");
		
		for(String item : items){
			mValue = dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("M", item);
			fValue = dbQuestionnaireSimpleSummary.getQuestionnaireSexScoreAvg("F", item);
			fQuestionnaireSexChart = new ChartSexBean("", "", 0, 0);
			if(!(mValue == 0 & fValue == 0)){
				fQuestionnaireSexChart.setSerieas(libFunction.ItemNameConvert(item));
				fQuestionnaireSexChart.setCategory(libFunction.ItemNameConvert(item));
				fQuestionnaireSexChart.setmValue(mValue);
				fQuestionnaireSexChart.setfValue(fValue);
				fQuestionnaireSexCharts.add(fQuestionnaireSexChart);
			}
		}
		return fQuestionnaireSexCharts;
	}
	
	public List<ChartSexBean> getOtherSexChart(){
		List<ChartSexBean> otherSexCharts = new ArrayList<ChartSexBean>();
		ChartSexBean otherSexChart;
		double mValue, fValue, mfTotal;
		List<String> items = new ArrayList<String>();
		items.add("totalscore");
		items.add("dtotalscore");
		items.add("ftotalscore");
		items.add("BMI");
		items.add("hwscore");
		items.add("total");

		for(String item : items){
			mValue = dbStudentSummaryService.getStudentSexScoreAvg("M", item);
			fValue = dbStudentSummaryService.getStudentSexScoreAvg("F", item);
			
			mfTotal = mValue + fValue;
			mValue = (mValue/mfTotal) * 100;
			fValue = (fValue/mfTotal) * 100;
			
			otherSexChart = new ChartSexBean("", "", 0, 0);
			otherSexChart.setSerieas(libFunction.ItemNameConvert(item));
			otherSexChart.setCategory(libFunction.ItemNameConvert(item));
			otherSexChart.setmValue(mValue);
			otherSexChart.setfValue(fValue);
			otherSexCharts.add(otherSexChart);
		}
		return otherSexCharts;
	}
	
	public List<Double> getOtherSexChartTable(String item, double lower, double height){
		List<Double> values = new ArrayList<Double>();
		double mLower, mHeight, fLower, fHeight, mLevelValue, fLevelValue, min, max;
		if(lower == 0 & height == 0){
			mLower = dbStudentSummaryService.getStudentSexScoreMaxMin("M", item, "MIN");
			mHeight = dbStudentSummaryService.getStudentSexScoreMaxMin("M", item, "Max");
			fLower = dbStudentSummaryService.getStudentSexScoreMaxMin("F", item, "MIN");
			fHeight = dbStudentSummaryService.getStudentSexScoreMaxMin("F", item, "Max");
		}else{
			mLower = lower;
			mHeight = height;
			fLower = lower;
			fHeight = height;
		}
		
		mLevelValue = (mHeight - mLower) / 5;
		fLevelValue = (fHeight - fLower) / 5;
		
		for(int Score=1; Score<=5; Score++){
			min = mLower + (mLevelValue * (Score - 1));
			max = mLower + (mLevelValue * Score);
			values.add((double)dbStudentSummaryService.getStudentSexScoreCount("M", item, min, max));
		}
		values.add((double)dbStudentSummaryService.getStudentSexScoreCount("M", item, mLower, mHeight));
		values.add(libFunction.doublePoint(dbStudentSummaryService.getStudentSexScoreAvg("M", item)));
		for(int Score=1; Score<=5; Score++){
			min = fLower + (fLevelValue * (Score - 1));
			max = fLower + (fLevelValue * Score);
			values.add((double)dbStudentSummaryService.getStudentSexScoreCount("F", item, min, max));
		}
		values.add((double)dbStudentSummaryService.getStudentSexScoreCount("F", item, mLower, mHeight));
		values.add(libFunction.doublePoint(dbStudentSummaryService.getStudentSexScoreAvg("F", item)));
		
		return values;
	}
}
